/**
 * @author Yuliy Khorolinskyy
 *
 * Reaktionsspiel data
 *
 * 02.01.2012
 */
package data;

import java.util.Calendar;
import java.util.Date;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlEnum;

/**
 * @author Yuliy
 *
 */
public class HighscoreEntry implements Comparable<HighscoreEntry> {
	@XmlEnum
	public static enum DIFFICULTY{EASY,MEDIUM,HARD,ALL,UNDEFINED};
	
	private String playerName;
	private DIFFICULTY difficulty;
	private int score;
	
	private Calendar date;

	private HighscoreEntry(){
		this("defaultPlayer", DIFFICULTY.UNDEFINED, -1, Calendar.getInstance());
		
	}
	
	public HighscoreEntry(String playerName, DIFFICULTY difficulty, int score, Calendar date) {
		this.playerName = playerName;
		this.difficulty = difficulty;
		this.score = score;
		this.date = date;
	}

	public String getPlayerName() {
		return playerName;
	}

	public DIFFICULTY getDifficulty() {
		return difficulty;
	}

	public int getScore() {
		return score;
	}

	public Calendar getDate() {
		return date;
	}


	public void setPlayerName(String playerName) {
		this.playerName = playerName;
	}

	public void setDifficulty(DIFFICULTY difficulty) {
		this.difficulty = difficulty;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public void setDate(Calendar date) {
		this.date = date;
	}

	@Override
	public int compareTo(HighscoreEntry oHs) {
		if(oHs == null) return  1;
		else if(oHs.getDifficulty().ordinal() < this.getDifficulty().ordinal())return 1;
		else if(oHs.getDifficulty().ordinal() > this.getDifficulty().ordinal())return -1;
		else{
			if(oHs.getScore() < this.getScore()) return 1;
			else if(oHs.getScore() > this.getScore())return -1;
			else{
				if(oHs.getDate().before((this.getDate())))return 1;
				else if(this.getDate().before((oHs.getDate()))) return -1;
				else return 0;
			}
		}
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null || !(obj instanceof HighscoreEntry)) return false;
		else{
			if(((HighscoreEntry) obj).getDifficulty() == this.getDifficulty() 
				&& ((HighscoreEntry) obj).getScore() == this.getScore()
				&& ((HighscoreEntry) obj).getDate().equals(this.getDate())
				&& ((HighscoreEntry) obj).getPlayerName().equals(this.getPlayerName())) return true;
		}
		return false;
	}
	

}


